﻿using System.Linq;
using System.Collections.Generic;
using BusinessObjects.ValidationRules;

namespace BusinessObjects
{
    // Domain Model Pattern
    public class Customer : BusinessObject
    {
        public string CustomerId { get; set; }
        public string CompanyName { get; set; }
        public string Name { get; set; }
        public List<Order> Orders { get; set; }

        public Customer()
        {
            AddRule(new ValidateMandatory("CustomerId"));
        }

        public bool IsAllowedDiscount()
        {
            var allowDiscount = Orders.All(x => x.OrderDetails.Sum(y => y.Quantity) > 10);

            return allowDiscount;
        }
    }
}
